package org.robot.scm.pojos.config;

import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.robot.scm.pojos.config.base.BasePlatform;
import org.robot.scm.pojos.config.base.BaseUser;
import org.robot.scm.pojos.enums.PlatformEnum;
import org.robot.scm.utils.StreamUtils;

/**
 * @Author : Awn create on 2023/10/19 11:25
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class MainConfig {

    /**
     * 允许的平台，逗号隔开
     */
    private List<String> enables;

    /**
     * 启动通知
     */
    private boolean startNotify;

    /**
     * 勿扰模式配置
     */
    private NightMode nightMode;

    /**
     * 通知渠道配置
     */
    private ConfigChannel notifyChannel;

    /**
     * 平台详细配置
     */
    private List<BasePlatform> platforms;

    /**
     * 渠道用户配置
     */
    private ConfigUser userInfo;


    /**
     * 配置转换，获取制定平台的用户bark配置
     */
    public List<String> getBarks(PlatformEnum platformEnum) {
        List<BaseUser> baseUsers = StreamUtils.filter(getUserInfo().getBark(), e -> e.getEnables().contains(platformEnum.getVal()));
        return StreamUtils.convertAndDistinct(baseUsers, BaseUser::getDeviceId);
    }

    /**
     * 配置转换，获取制定平台的用户机器人配置
     */
    public List<String> getRobots(PlatformEnum platformEnum) {
        List<BaseUser> baseUsers = StreamUtils.filter(getUserInfo().getRobot(), e -> e.getEnables().contains(platformEnum.getVal()));
        return StreamUtils.convertAndDistinct(baseUsers, BaseUser::getDeviceId);
    }

    /**
     * 配置转换，获取制定平台的用户pushme配置
     */
    public List<String> getPushme(PlatformEnum platformEnum) {
        List<BaseUser> baseUsers = StreamUtils.filter(getUserInfo().getPushme(), e -> e.getEnables().contains(platformEnum.getVal()));
        return StreamUtils.convertAndDistinct(baseUsers, BaseUser::getDeviceId);
    }

    public BasePlatform getPlatform(PlatformEnum platformEnum) {
        return StreamUtils.filterOne(platforms, e -> StringUtils.equals(e.getPlatformName(), platformEnum.getVal()));
    }
}
